<template>
  <div>
    <el-row>
      <el-col class="buttons-row">
        <el-button type="primary" size="mini" @click="editRules">设置</el-button>
      </el-col>
    </el-row>
    <div>
      <!-- Table -->
      <el-table :data="tableData" class="table_content"
                :header-cell-style="{color:'#2A2A2A'}"
                border style="width: 100%; margin-top: 5px" :fit="true"
                height="765"
      >
        <el-table-column type="index" label="序号" width="50"></el-table-column>
        <el-table-column prop="machineStation" label="工站" width="100"></el-table-column>
        <el-table-column prop="alarmCode" label="报警代码" width="100"></el-table-column>
        <el-table-column prop="alarmLevel" label="报警等级" width="80"></el-table-column>
        <el-table-column prop="alarmInfo" label="报警信息" width="200"></el-table-column>
        <el-table-column prop="solution" label="解决方案"></el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DeviceRules',
  data() {
    return {
      tableData: [],
      query: {
        type: "42",
      }
    };
  },
  props: {
    qtCall: {
      type: Object,
      default: null
    }
  },
  mounted() {
    if (process.env.NODE_ENV === 'production') {
      setTimeout(() => {
        if (this.qtCall) {
          this.fetchData();
        }
      }, 200);
    } else {
      this.fetchData();
    }
  },
  methods: {
    editRules() {
      console.log('设置按钮点击;');
      if (process.env.NODE_ENV === 'production') {
        this.query.type = 42;
        this.qtCall.JsToQt("NeedOperate", this.query);  //可以传给qt
      }
    },
    fetchData() {
      let getTableData = [];
      console.log("rules page ！")
      if (process.env.NODE_ENV === 'production') {
        this.qtCall.JsToQt("NeedRefreshMachineAlarmsInDeviceManagement", {});
        this.qtCall.QtToJs.connect((func, json) => {
          if (func === "RefreshMachineAlarmsInDeviceManagement") {
            const datas = JSON.parse(json)
            if (datas.code === 200) {
              console.log("datas.data[MachineAlarms]: ", datas.data["MachineAlarms"])
              this.tableData = datas.data["MachineAlarms"]
            }
          }
        })
      } else {
        getTableData = [
          {
            "machineStation": "工站1",
            "alarmLevel": "报警等级",
            "alarmCode": "报警代码",
            "alarmInfo": "报警信息",
            "solution": "解决方案"
          }
        ]
        this.tableData = getTableData;
      }
    },
  }
};
</script>

<style scoped>
.table_content {
  font-size: 14px;
  height: 70vh;
  overflow-y: auto;
}
</style>
